home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1996 #15
/
Monster Media Number 15 (Monster Media)(July 1996).ISO
/
prog_c
/
cuj0696.zip
/
DWYER.ZIP
/
POKER.TST
/
README.PKR
< prev
next >
Wrap
Text File
|
1996-01-04
|
9KB
|
233 lines
DESCRIPTION OF THE POKER TEST
Introduction
------------
This test is also called the partition test. In a classical
Poker test, N groups of five successive integers are examined
for one of the following seven patterns [K1, p. 62]::
All different: abcde
One pair: aabcd
Two pairs: aabbc
Three of a kind: aaabc
Full house: aaabb
Four of a kind: aaaab
Five of a kind: aaaaa
In our implementation, N groups of k successive random integers
are examined. Instead of counting the occurrence of the patterns
shown above, we count the number of _distinct_ values in each set
of k numbers. For example, when k = 5 we search for one of the
following five patterns:
5 different = all different
4 different = one pair
3 different = two pairs, or three of a kind
2 different = full house, or four of a kind
1 different = five of a kind
One can imagine Hoyle whirring in his grave [M1].
This test is easier to implement than the classical Poker test
and Knuth [K1, p. 62] suggests that it is almost as good. The
classical Poker test uses groups more closely related to the
card game, but this test is both easier to implement and more
flexible because the number of elements in a pattern can range
from four to eight. When k = 6, for example, the search is on
one of six patterns:
6 different = all different
5 different = one pair
4 different = two pairs, or three of a kind
3 different = full house, four of a kind, or three pair
2 different = two of three of a kind, five of a kind,
or four of a kind and a pair
1 different = six of a kind
The code fragment that performs this test in shown in listing1.pkr.
The idea is to start by assuming that all cards are different. When
two cards are matched, the number different is decremented by one.
The search starts with the first card and the remaining cards in the
deck are scanned. Then the second card is matched with the remaining
cards (those that follow) unless it has already been matched, etc.
The outer loop (line 7) moves through the deck, one card at a time.
If the card has not already been matched (line 9), the inner loop
compares its value with those remaining (line 13).
The probabilities associated with these patterns is calculated
as follows:
Let k be the number of elements in a pattern and r be
the number of different values. Then, the probability
that there are r different values in the pattern is
d(d-1)...(d-r+1) | [r] is subscript r
p[r] = ----------------{k,r} | ^k is exponent k
d^k | {k,r} should be
| large { with k & r
| stacked like this:
| k
| r
where {k,r} is a Stirling number of the second kind.|
A Stirling number of the second kind, {k,r}, is the number of ways
of partitioning k elements into r non-empty subsets ([H1], page 824).
The Poker test is implemented as program pokertst. This program
performs a Kolmogorov-Smirnov analysis on probabilities from 100
chi-square tests. The parameters that determine how the chi-square
tests are performed are specified by the user. These parameters
are read from the console unless the input device is redirected.
As usual, prompts and messages are written to stderr and results
are written to stdout.
Running the Poker Test
----------------------
To start program gaptst, you can say simply
pokertst
and you will be prompted for the required inputs.
Alternatively, you can say
pokertst < [myfile.inp]
and the program will take its input data from myfile.inp.
Seven input parameters are required:
1. Seed for the random number generator (-1 = Time of day)
If you do not specify -1, the value entered must be less
than 65536.
2. Specification of generator to be tested
If you are working interactively, you will see a list
of the generators that can be selected. You enter the
character that represents your generator. If you enter
a character that is not in the list, the library rand()
function will be used.
3. Number of cards per hand to be dealt [4-8]
You can select a number between 4 and 8. If you enter a
number less than 4, 4 will be assigned. In your entry is
greater than 8, 8 will be assigned.
4. Number of unique cards in random deck [10-128]
The limits have been assigned based on experience. Most
of the test runs were conducted using the number 10. If
your entry is less than 10, 10 will be assigned.
5. Minimum cell expectation [5-10]
A cell is the same thing as a category. Enter the expected
number of events per category (also called a pattern in the
introduction). The lower limit of five is Knuth's suggestion
for all these tests. The upper limit of 10 is arbitrary and
you can change it by redefining MAX_CELL_XPCT in header file
pokrdefs.h.
6. Number of hands per run that should be dealt [xxx ...]
The program makes 100 runs to calculate chi-square statistics.
The number that you enter here specifies the number of hands
that will be used to calculate chi-square. The xxx shown in
brackets will be a number that guarantees that at least four
cards in a hand will be used.
Execution of the Algorithm
--------------------------
Once the input parameters have been processed and run-control
variables have been set, the program will execute 100 chi-square
runs as dictated by the input:
1. The program deals the number of hands specified at input 6.
Each hand consists of the number of cards per hand that you
specified at step 3. Each 'card' is created by calling the
generator that you specified at input 2. The output of the
generator modulo the number that you specified at input 4 is
used as a 'card.'
2. When a complete hand is collected, its pattern is determined.
This pattern is one of the five possible as described in the
introduction.
3. The number different is used as an index and the corresponding
counter in an array is tallied.
4. A chi-square statistic is calculated for the array of tallies.
5. A probability for the chi-square statistic is calculated.
6. The probability is stored in an array.
7. A running account of the steps and the number of variates
generated lets you know that the program is executing.
When the 100 runs are complete, a Kolmogorov-Smirnov test is run on
the array to obtain statistics Kn+ and Kn- and their corresponding
probabilities.
Final printouts consist of the Kolmogorov-Smirnov statistics and
probabilities and the number of random numbers generated during the
test.
Figure.1p shows a sample input file should you elect to redirect the
input. Figure.2p shows what you can expect to see if you redirect the
output during the run on the sample input shown in figure 1p. Figure.3p
shows what your screen should look like if you redirect stdout to a file.
Error Printouts
---------------
o Not enough hands were specified
"Of the 5 Possible Categories, 1 Has a Cell Expectation Less Than
the Number Requested (5) and Will be Lumped With Others."
"For the Inputs That You Have Provided At Least 50000 Hands are Required
to Fill All Categories."
These printouts will occur if you do not enter a large enough number at
input step 6 (above). The number of cards per hand will be reduced until
your cell expectation can be met with the number of hands that you wanted
to be dealt. The minimum number of cards per hand is four.
If the number that you specify at input step 6 is less that the number
the appears in the prompt, you have committed a fatal error. Here is
a sample of what is printed:
"At Least 4 Cards Per Hand Are Required.
Your Inputs Allow Only 3."
Timing Estimates
----------------
The run shown in figure.1p required about 1.8 seconds on my
Pentium 100. Naturally, the time required depends on the
generator (and the CPU). For the data shown, the range of
times is from 1.8 seconds for the MSC library function rand()
to 8.8 seconds for the generator by Stephen L. Moshier.
Both tests required exactly 1,000,000 random numbers.
REFERENCE
H1. Handbook of Mathematical Tables, ed. by M. Abramowitz
and I. A. Stegun (Washington, D.C.: U.S. Gov't Printing
Office, 1964).
M1. Albert H. Morehead et al, The New Complete Hoyle Revised,
Doubleday, London (1981). According to this book, Edmond
Hoyle (1672-1769) died at least 50 years before Poker was
invented.